package com.future.mayi.activity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewStub;
import android.view.animation.AnimationSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.future.mayi.R;

import butterknife.ButterKnife;


/**
 * Created by 周大虎 on 2016/12/1.
 */

public abstract class BaseTitleActivity extends BaseActivity implements View.OnClickListener {
    protected RelativeLayout rlActivityMain;
    protected RelativeLayout rlMainTitle;
    private View viewMainLine;
    private FrameLayout fragmentMain;
    private ViewStub leftViewStub, rightViewStub, titleViewStub;
    private TextView leftTextView, rightTextView, titleTextView;
    private ImageView leftImageView, rightImageView;
    private LinearLayout llMessage;
    private TextView tvMessage;
    private TextView tvTitleMessageNum;
    private AnimationSet mInAnimationSet;
    private Handler handler;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.setContentView(R.layout.activity_layout_base);
        rlActivityMain = (RelativeLayout) findViewById(R.id.rl_activity_main);
        rlMainTitle = (RelativeLayout) findViewById(R.id.rl_main_title);
        viewMainLine = findViewById(R.id.view_main_line);
        fragmentMain = (FrameLayout) findViewById(R.id.fragment_main_base);
        leftViewStub = (ViewStub) findViewById(R.id.vs_main_left);
        rightViewStub = (ViewStub) findViewById(R.id.vs_main_right);
        titleViewStub = (ViewStub) findViewById(R.id.vs_main_title);

        //设置titleBar
        initTopBar();
        super.onCreate(savedInstanceState);
    }


    protected abstract void initTopBar();

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.iv_title_left) {
            onBackPressed();
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        View contentView = getLayoutInflater().inflate(layoutResID, null);
        fragmentMain.addView(contentView);
        ButterKnife.bind(this);
    }

    @Override
    public void setContentView(View view) {
        fragmentMain.addView(view);
        ButterKnife.bind(this);
    }


    protected void setTitleColors(int color) {
        rlMainTitle.setBackgroundColor(getResources().getColor(color));
    }


    protected void setMainVisibility(int visibility) {
        findViewById(R.id.rl_activity_main).setVisibility(visibility);
    }

    protected void setViewLineVisibility(int visibility) {
        viewMainLine.setVisibility(visibility);
    }

    protected TextView getTitleText() {
        if (titleViewStub == null)
            return null;
        if (titleTextView == null) {
            titleViewStub.setLayoutResource(R.layout.layout_base_title_text);
            titleTextView = (TextView) titleViewStub.inflate();
        }
        return titleTextView;
    }

    protected TextView getLeftText() {
        if (leftViewStub == null || leftImageView != null)
            return null;
        if (leftTextView == null) {
            leftViewStub.setLayoutResource(R.layout.layout_base_left_text);
            leftTextView = (TextView) leftViewStub.inflate();
        }
        return leftTextView;
    }

    protected TextView getRightText() {
        if (rightViewStub == null || rightImageView != null)
            return null;
        if (rightTextView == null) {
            rightViewStub.setLayoutResource(R.layout.layout_base_right_text);
            rightTextView = (TextView) rightViewStub.inflate();
            rightTextView.setOnClickListener(this);
        }
        return rightTextView;
    }

    protected ImageView getLeftImg() {

        if (leftViewStub == null || leftTextView != null)
            return null;
        if (leftImageView == null) {
            leftViewStub.setLayoutResource(R.layout.layout_base_left_img);
            leftImageView = (ImageView) leftViewStub.inflate();
            leftImageView.setOnClickListener(this);
        }
        return leftImageView;
    }


    protected void initBack() {
        getLeftImg().setImageResource(R.drawable.back);
    }

    protected ImageView getRightImg() {
        if (rightViewStub == null || rightTextView != null)
            return null;
        if (rightImageView == null) {
            rightViewStub.setLayoutResource(R.layout.layout_base_right_img);
            rightImageView = (ImageView) rightViewStub.inflate();
        }
        return rightImageView;
    }




}
